package Coordinates;
import Dungeon.Dungeon;
import be.kuleuven.cs.som.annotate.Basic;

public class Coordinates {
	
	
	
	/**
	 * Creates a new set of coordinates from given x, y and z values
	 * @param 	x
	 * 			The X-coordinate for the new set of coordinates 
	 * @param 	y
	 * 			The Y-coordinate for the new set of coordinates 
	 * @param 	z
	 * 			The Z-coordinate for the new set of coordinates 
	 * @post	The x coordinate equals the given value
	 * 			| new.getX() == x
	 * @post	The y coordinate equals the given value
	 * 			| new.getY() == y
	 * @post	The z coordinate equals the given value
	 * 			| new.getZ() == z
	 */
	public Coordinates(long x, long y, long z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	/**
	 * 
	 * @param 	dungeon
	 * 			The dungeon to check the coordinates in.
	 * @param 	x
	 * 			The X-coordinate
	 * @param 	y
	 * 			The Y-coordinate
	 * @param 	z
	 * 			The Z-coordinate
	 * @return	Returns true if and only if the given coordinates are valid for the given dungeon, returns false in all other cases.
	 * 			| if(x == y && y == z)
	 * 			| 	result == false
	 * 			| else if( x > dungeon.getDimension(Axis.X_AXIS) || y > dungeon.getDimension(Axis.Y_AXIS) || z > dungeon.getDimension(Axis.Z_AXIS))
	 * 			|	result == false
	 * 			| else
	 * 			| 	result == true
	 */ 
	static public boolean areValidCoordinates(Dungeon<?> dungeon, long x, long y, long z)
	{
		if(x == y && y == z)
			return false;
		else if( x >= dungeon.getDungeonDimensions(Axis.X_AXIS) || y >= dungeon.getDungeonDimensions(Axis.Y_AXIS) 
				|| z >= dungeon.getDungeonDimensions(Axis.Z_AXIS))
			return false;
		else
			return true;
	}
	
	/**
	 * Returns the X coordinate of this set of coordinates
	 * 
	 */
	@Basic
	public long getX()
	{
		return this.x;
	}
	
	/**
	 * A variable containing the x-coordinate
	 */
	private long x;
	
	/**
	 * Returns the Y coordinate of this set of coordinates
	 * 
	 */
	@Basic
	public long getY()
	{
		return this.y;
	}
	
	/**
	 * A variable containing the y-coordinate
	 */
	private long y;
	
	/**
	 * Returns the Z coordinate of this set of coordinates
	 * 
	 */
	@Basic
	public long getZ()
	{
		return this.z;
	}
	
	/**
	 * A variable containing the z-coordinate
	 */
	private long z;
	
	/**
	 * A method to check whether this object equals another
	 * 
	 * @return	True if the objects are equal, false if they're not
	 */
	@Override
	public boolean equals(Object obj) {
        if (obj == null) return false;
        if (!this.getClass().equals(obj.getClass())) return false;
                
        if( ((Coordinates)obj).getX() == getX() && ((Coordinates)obj).getY() == getY() && ((Coordinates)obj).getZ() == getZ())
        	return true;
        else
        	return false;
        
    }
	
	/**
	 * Gets a hashcode for this set of coordinates
	 * 
	 * @return a hashcode for this set of coordinates
	 */
	@Override
	 public int hashCode() {
	    String string = getX() + "_" + getY() + "_" + getZ();
	    return string.hashCode();
	 }
		
}
